//
// Created by QU on 24-6-10.
//
#include <iostream>
#include <fstream>
#include <sstream>
#include <functional>
#include <utility>
#include <memory>
#include <vector>
#include <map>
#include <set>

using std::cout, std::cin, std::endl, std::unitbuf;

struct int_char
{
    int i;
    char c;
};

int main()
{
    // 使用 make_tuple 创建一个 tuple
    std::tuple<int, int_char, std::string> example_tuple{12, {1, 'c'}, "aquawius"};

    auto my_tuple = std::make_tuple(1, 2.5, std::string("Hello"));
    // 访问 tuple 的元素
    std::cout << std::get<0>(my_tuple) << std::endl; // 输出: 1
    std::cout << std::get<1>(my_tuple) << std::endl; // 输出: 2.5
    std::cout << std::get<2>(my_tuple) << std::endl; // 输出: Hello

    // 如果不知道一个tuple 准确的类型细节信息， 可以用两个辅助类模板来查询 tuple 成员的数量和类型：
    typedef decltype(my_tuple) trans; // 推断类型  这里的trans是mk_tuple的类型
    // 你可以将下面的decltype(my_tuple) 换成trans, 结果是一样的.

    // 获取 tuple 的元素个数
    // constexpr std::size_t tuple_size = std::tuple_size<decltype(example_tuple)>::value;
    constexpr std::size_t tuple_size = std::tuple_size_v<decltype(example_tuple)>;
    std::cout << "Tuple size: " << tuple_size << std::endl;

    // 获取第一个元素的类型
    // using FirstType = std::tuple_element<0, decltype(example_tuple)>::type;
    using FirstType = std::tuple_element_t<0, decltype(example_tuple)>;
    std::cout << "First element type: " << typeid(FirstType).name() << std::endl;

    // 获取第二个元素的类型
    using SecondType = std::tuple_element<1, decltype(example_tuple)>::type;
    std::cout << "Second element type: " << typeid(SecondType).name() << std::endl;

    // 获取第三个元素的类型
    using ThirdType = std::tuple_element<2, decltype(example_tuple)>::type;
    std::cout << "Third element type: " << typeid(ThirdType).name() << std::endl;

    // 检查类型是否匹配
    bool is_first_int = std::is_same<FirstType, int>::value;
    std::cout << "Is first element int? " << (is_first_int ? "Yes" : "No") << std::endl;


    return 0;
}
